package org.healthy.model.page;

import java.util.List;

/**
 * 分页对象
 */
public class Pagination<T> {
    //分页类型(pageNo分页方式，适用于数据量变化不大的情况)
    public final static int TYPE_PAGE_NO = 0;
    //分页类型(pageNum方式适用于数量量变更，新增比较频繁的数据)
    public final static int TYPE_START_NUM = 1;

    private List<T> values;

    //升序
    public final static int SORT_ASC = 1;
    //降序
    public final static int SORT_DESC = 0;

    public Integer getStart() {
        return (pageNo - 1) * pageSize;
    }

    public Long getEnd() {
        return (long) (pageNo * pageSize - 1);
    }

    //分页类型
    public Integer pageType;

    public List<T> getValues() {
        return values;
    }

    public void setV(List<T> v) {
        this.values = v;

    }


    public Pagination(int pageNo, int pageSize, List<T> items) {
        this.pageNo = pageNo;
        this.pageSize = pageSize;
        this.values = items;

    }


    public Pagination(Integer pageNo, Integer pageSize) {
        this.pageNo = pageNo;
        this.pageSize = pageSize;
        this.pageType = TYPE_PAGE_NO;
    }

    public Pagination(Long startNum, Integer pageSize) {
        this.startNum = startNum;
        this.pageSize = pageSize;
        this.pageType = TYPE_START_NUM;
    }

    public Integer pageNo = 1;
    private Integer pageSize = 15;
    private Long startNum = -1L;


    public Long getStartNum() {
        return startNum;
    }

    public void setStartNum(Long startNum) {
        this.startNum = startNum;
    }

    public Boolean isEnd() {
        return end;
    }

    public void setEnd(Boolean end) {
        this.end = end;
    }

    private Boolean end;

    public Integer getPageNo() {
        return pageNo;
    }

    public void setPageNo(Integer pageNo) {
        this.pageNo = pageNo;
    }

    public Integer getPageSize() {
        return pageSize;
    }

    public void setPageSize(Integer pageSize) {
        this.pageSize = pageSize;
    }

    public Pagination nextPage() {
        this.pageNo++;
        return this;
    }


    public Boolean isFristPage() {
        return pageNo == 1;
    }


}
